package cn.bluemobi.dylan.step.ui.my.activity;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import cn.bluemobi.dylan.step.R;
import cn.bluemobi.dylan.step.base.BaseMvpActivity;
import cn.bluemobi.dylan.step.moder.bean.User;
import cn.bluemobi.dylan.step.presenter.contract.my.MyInfoContract;
import cn.bluemobi.dylan.step.presenter.my.activity.MyInfoPresenter;

public class MyInfoActivity extends BaseMvpActivity<MyInfoPresenter> implements MyInfoContract.View {

    @BindView(R.id.img_head)
    ImageView img_head;
    @BindView(R.id.tv_nickname)
    TextView tv_nickname;
    @BindView(R.id.tv_phone)
    TextView tv_phone;
    @BindView(R.id.btn_exit)
    TextView btn_exit;
    @BindView(R.id.img_nickname)
    ImageView img_nickname;
    private User user;

    @Override
    protected int getLayout() {
        return R.layout.my_info;
    }

    @Override
    protected void initView() {
        super.initView();
        mPresenter.preUser();
    }

    private void initInfo(){
//        Glide.with(this).load(user.memberPhone).into(img_head);
        img_head.setImageResource(R.mipmap.my_head);
        if(user!=null){
            if(!TextUtils.isEmpty(user.memberNickName)){
                tv_nickname.setText(user.memberNickName);
            }

            tv_phone.setText(user.memberPhone);
        }
    }

    @OnClick({R.id.img_nickname,R.id.btn_exit})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.img_nickname:
                Intent intent = new Intent(this,InfoEditActivity.class);
                intent.putExtra("User",user);
                startActivityForResult(intent,1);
                break;
                case R.id.btn_exit:
                    setResult(1);
                    this.finish();
                break;
        }
    }


    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }


    @Override
    public void showError(String msg) {

    }

    @Override
    public void showDialog() {

    }

    @Override
    public void closeDialog() {

    }

    @Override
    public void showContent(User user) {
        this.user = user;
        initInfo();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==1 && resultCode==1){
            if(data!=null){
                user = (User) data.getSerializableExtra("User");
                initInfo();
            }
        }
    }
}
